﻿<UserControl x:Class="Deployment.Data.UI.Controls.Environment.EnvironmentsEditorControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:environment="clr-namespace:Deployment.Data.UI.Controls.Environment"
             xmlns:connection="clr-namespace:Deployment.Data.UI.Controls.Connection"
             xmlns:converter="clr-namespace:Deployment.Data.UI.Converters"
             xmlns:Properties="clr-namespace:Deployment.Data.UI.Properties"
             mc:Ignorable="d" d:DesignWidth="300" >
    <UserControl.Resources>
        <converter:ObjectToAbstractConnectionControl x:Key="ObjToControl"/>
    </UserControl.Resources>
    <DockPanel>
        <Grid DockPanel.Dock="Top" Margin="4">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="{Binding EnvironmentEditorControl_Environments_Height, Source={x:Static Properties:Settings.Default}, Mode=TwoWay}"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>

            <Label Content="Environment file path:"
                   Grid.Row="0" Grid.Column="0"
                   VerticalAlignment="Top"/>
            <TextBlock Grid.Row="0" Grid.Column="1" 
                       TextWrapping="Wrap" 
                       x:Name="tbl_EnvironmentsFilePath"
                       VerticalAlignment="Center"
                       Text="{Binding ElementName=EditorControl, Path=EnvironmentsFilePathText}"/>

            <Label Content="Environments:"
               Grid.Column="0" Grid.ColumnSpan="2"
               Grid.Row="1"/>

            <environment:EnvironmentEditableList Grid.Row="2"
                                                 Grid.Column="0" Grid.ColumnSpan="2"
                                                 x:Name="EnvironmentList"
                                                 DataContext="{Binding}"/>

            <GridSplitter Grid.Row="3"
                          Grid.Column="0"
                          Grid.ColumnSpan="2"
                          HorizontalAlignment="Stretch"
                          VerticalAlignment="Stretch"
                          ShowsPreview="True"
                          ResizeBehavior="PreviousAndCurrent"
                          ResizeDirection="Rows"
                          Height="5"/>

            <GroupBox Grid.Row="4"
                      Grid.Column="0" Grid.ColumnSpan="2"
                      Header="Environment Connections">

                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="{Binding EnvironmentEditorControl_Connections_Height, Source={x:Static Properties:Settings.Default}, Mode=TwoWay}"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="{Binding EnvironmentEditorControl_ConnectionDetails_Height, Source={x:Static Properties:Settings.Default}, Mode=TwoWay}"/>
                    </Grid.RowDefinitions>

                    <connection:ConnectionEditableList Grid.Row="0"
                                                       x:Name="ConnectionList"
                                                       ClipToBounds="True"
                                                       VerticalContentAlignment="Stretch"
                                                       DataContext="{Binding ElementName=EnvironmentList, Path=SelectedEnvironment}">
                        <connection:ConnectionEditableList.Style>
                            <Style>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding ElementName=EnvironmentList, Path=SelectedEnvironment}"
                                                 Value="{x:Null}">
                                        <Setter Property="connection:ConnectionEditableList.IsEnabled"
                                                Value="False"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </connection:ConnectionEditableList.Style>
                    </connection:ConnectionEditableList>

                    <GridSplitter Grid.Row="1"
                          Grid.Column="0"
                          Grid.ColumnSpan="2"
                          HorizontalAlignment="Stretch"
                          VerticalAlignment="Stretch"
                          ShowsPreview="True"
                          ResizeBehavior="PreviousAndCurrent"
                          ResizeDirection="Rows"
                          Height="5"/>

                    <GroupBox Grid.Row="2"
                              Header="Connection Details"
                              IsEnabled="False">
                        <ScrollViewer Margin="4" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"
                                      
                                      Content="{Binding ElementName=ConnectionList, Path=SelectedConnection, Converter={StaticResource ObjToControl}}"/>
                    </GroupBox>
                </Grid>
            </GroupBox>


        </Grid>
        <Button DockPanel.Dock="Bottom"
                HorizontalAlignment="Right"
                Padding="4"
                Margin="4"
                Content="Save Changes" Click="SaveButton_Click"/>
    </DockPanel>
</UserControl>
